require "dict"
require 'multctx_rbm'


torch.setdefaulttensortype('torch.DoubleTensor')

function main()

	-- load dic & embs
	print('load dic & emb')
	local f = torch.DiskFile(dic_emb_path, 'r')
	dic 	= f:readObject()	setmetatable(dic, Dict_mt)
	wemb 	= f:readObject()
	f:close()

	-- load data
	print('load data')
	f = torch.DiskFile(data_path, 'r')
	f:binary()
	data = f:readObject():double()
	data = shuffle(data)
	f:close()

	-- load sampler storage
	print('load sampler storage')
	f = torch.DiskFile(sampler_storage_path, 'r')
	f:binary()
	sampler_storage = f:readObject()
	f:close()

	-- training
		print('training...')

		nctxwords = data:size(1) - 1
		hiddim = 100

		init_momentum = 0.9
		final_momentum = 0.9
		eps = 0.01
		weightcost = 0.001
		chainlen = 150 

		nepoch = 100
		batchsize = 100

		local model = MultCtxRBM:new(wemb, nctxwords, hiddim)
	
		print('training rbms...')
		model:train(data, nepoch, batchsize, init_momentum, final_momentum, 
					eps, weightcost, chainlen, sampler_storage)
end

if #arg ~= 3 then
	print("<dic_emb_path> <data_path> <sampler_storage_path>")
else
	dic_emb_path			= arg[1]
	data_path				= arg[2]
	sampler_storage_path 	= arg[3]
	main()
end


